<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改位置')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-position-edit" th:object="${position}">
		<input name="id" type="hidden" th:field="*{id}" />
		<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
		<div class="form-group">
			<label class="col-sm-3 control-label">上级位置：</label>
			<div class="col-sm-8">
				<div class="input-group">
					<input class="form-control" type="text" id="treeName" onclick="selectPositionTree()" readonly="true" th:field="*{parentName}">
					<span class="input-group-addon"><i class="fa fa-search"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">位置名称：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="name" th:field="*{name}" id="name" required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label is-required">显示排序：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="orderNum" th:field="*{orderNum}" required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">描述：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="comment" th:field="*{comment}">
			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
	var prefix = ctx + "door/device/position";

	$("#form-dept-edit").validate({
		onkeyup: false,
		rules:{
			name:{
				remote: {
					url: prefix + "/checkPositionNameUnique",
					type: "post",
					dataType: "json",
					data: {
						"id": function() {
							return $("#id").val();
						},
						"parentId": function() {
							return $("input[name='parentId']").val();
						},
						"name": function() {
							return $.common.trim($("#name").val());
						}
					},
					dataFilter: function(data, type) {
						return $.validate.unique(data);
					}
				}
			},
			orderNum:{
				digits:true
			},
			email:{
				email:true,
			},
			phone:{
				isPhone:true,
			},
		},
		messages: {
			"name": {
				remote: "位置名称已经存在"
			}
		},
		focusCleanup: true
	});

	function submitHandler() {
		if ($.validate.form()) {
			$.operate.save(prefix + "/edit", $('#form-position-edit').serialize());
		}
	}

	/*部门管理-修改-选择位置树*/
	function selectPositionTree() {
		var id = $("#treeId").val();
		var excludeId = $("input[name='id']").val();
		if(id > 0) {
			var options = {
				title: '位置选择',
				width: "380",
				url: prefix + "/selectPositionTree/" + $("#treeId").val() + "/" + excludeId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		} else {
			$.modal.alertError("父位置不能选择");
		}
	}

	function doSubmit(index, layero){
		var tree = layero.find("iframe")[0].contentWindow.$._tree;
		if ($.tree.notAllowLastLevel(tree)) {
			var body = layer.getChildFrame('body', index);
			$("#treeId").val(body.find('#treeId').val());
			$("#treeName").val(body.find('#treeName').val());
			layer.close(index);
		}
	}
</script>
</body>
</html>
